"use strict";

exports.__esModule = true;
exports.default = void 0;

var Emitter =
  /*#__PURE__*/
  function () {
    function Emitter() {
      this.eventMap = {};
    }

    var _proto = Emitter.prototype;

    _proto.once = function once(evntName, callback) {
      var _this = this;

      this.on(evntName, function (data) {
        callback(data);

        _this.off(evntName, callback);
      });
    };

    _proto.on = function on(evtName, callback) {
      this.eventMap[evtName] = [callback];
      
      // if (this.eventMap[evtName]) {
      //   this.eventMap[evtName].push(callback);
      // } else {
      //   this.eventMap[evtName] = [callback];
      // }
    };

    _proto.off = function off(evtName, callback) {
      if (callback) {
        if (!this.eventMap[evtName]) {
          return;
        }

        var idx = this.eventMap[evtName].indexOf(callback);
        this.eventMap[evtName].splice(idx, 1);
      } else {
        delete this.eventMap[evtName];
      }
    };

    _proto.emit = function emit(evtName, data) {
      if (data === void 0) {
        data = {};
      }
      if (this.eventMap[evtName]) {
        this.eventMap[evtName].forEach(function (callback) {
          callback(data);
        });
      }
    };

    return Emitter;
  }();

exports.default = Emitter;